import request from '@/utils/request'

// 查询仓库列表
export function listWarehouse(query) {
  return request({
    url: '/system/warehouse/list',
    method: 'get',
    params: query
  })
}

// 查询仓库列表（DTO格式，用于下拉选择）
export function listWarehouseDTO(query) {
  return request({
    url: '/system/warehouse/list-dto',
    method: 'get',
    params: query
  })
}

// 查询仓库详细
export function getWarehouse(code) {
  return request({
    url: '/system/warehouse/' + code,
    method: 'get'
  })
}

// 新增仓库
export function addWarehouse(data) {
  return request({
    url: '/system/warehouse',
    method: 'post',
    data: data
  })
}

// 修改仓库
export function updateWarehouse(data) {
  // 允许改码时，后端可根据 oldCode 更新主键
  const payload = { code: data.code, name: data.name, enabled: data.enabled }
  if (data.oldCode) payload.oldCode = data.oldCode
  return request({
    url: '/system/warehouse',
    method: 'put',
    data: payload
  })
}

// 删除仓库
export function delWarehouse(code) {
  return request({
    url: '/system/warehouse/' + code,
    method: 'delete'
  })
}
